//
//  NYDetailChaptersViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYDetailChaptersViewController.h"
@interface NYDetailChaptersViewController ()

@end

@implementation NYDetailChaptersViewController
- (void)setDetailModel:(NYCourseModel *)detailModel
{
        _detailModel = detailModel;
        [self loadData];
}
- (void)setStartIndex:(NSInteger)startIndex
{
        _startIndex = startIndex;
        [self loadData];
}
- (void)viewDidLoad {
        [super viewDidLoad];
        [self loadData];
}
- (void)loadData
{
        if (self.isViewLoaded)
        {
                [self configNimbus];
                if (self.detailModel.video.count <= 0) {
                        [self hideEmptyView];
                        [self showEmptyViewWithText:@"暂无章节" detailText:@"" buttonTitle:nil buttonAction:nil];
                } else {
                        [self.tableViewModel addObjectsFromArray:self.detailModel.video];
                        [self.tableView reloadData];
                }
                [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:self.startIndex inSection:0] animated:NO scrollPosition:(UITableViewScrollPositionNone)];
        }
}
- (void)configNimbus
{
        [super configNimbus];
        [self.tableViewActions attachToClass:[NYVideoModel class] tapBlock:^BOOL(NYVideoModel * object, NYDetailChaptersViewController * target, NSIndexPath *indexPath) {
                if (indexPath.row == self.startIndex) {
                        return NO;
                }
                self.startIndex = indexPath.row;
                if (target.detailChaptersPlayBlock) {
                        target.detailChaptersPlayBlock(target.detailModel, object,indexPath.row);
                }
                return NO;
        }];
}
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (indexPath.row == self.startIndex) {
                return nil;
        }
        return indexPath;
}

@end
